/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import authentication.AuthenticationPort;
import authentication.EncryptionType;
import data.email.AccountType;
import java.util.Observable;

/**
 * Třída uchovávající data pro e-mailový účet. S jeho pomocí se vytvářejí účty, 
 * slouží také pro práci s odpojenou instancí.
 * @author Arcanis
 */
public class AccountData extends Observable{

    private String login = "";
    private String pass = "";    
    private AccountType type = AccountType.POP3;
    private String server = "";
    private EncryptionType encryption = EncryptionType.none;     
    private int customPort = 0;

    public AccountData() {
    }

    public void setLogin(String login) {
        this.login = login;
        setChanged();
    }

    public String getLogin() {
        return login;
    }

    public void setPass(String pass) {
        this.pass = pass;
        setChanged();
    }

    public String getPass() {
        return pass;
    }

    public void setServer(String server) {
        this.server = server;
        setChanged();
    }

    public String getServer() {
        return server;
    }

    public void setType(AccountType type) {
        this.type = type;
        setChanged();
    }

    public AccountType getType() {
        return type;
    }
    
    public void setEncryption(EncryptionType encryption) {
        this.encryption = encryption;
        setChanged();
    }

    public EncryptionType getEncryption() {
        return encryption;
    }
    
    public void setPort(int port) {
        this.customPort = port;
    }
    
    
    public int getPort() {
        if (this.customPort == 0) {
            // Get the default port
            AuthenticationPort authPort = AuthenticationPort.findPort(this.encryption, this.type);
            if (authPort != null) {
                return authPort.getPort();
            }
            else {
                return 0;
            }
        }
        else {
            return this.customPort;
        }
    }
}
